package na.learn.java.smalltests;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

public class testCons {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Class[] integerCls = { Integer.class };
		Class[] intCls = { int.class };
		System.out.println("Class of int is: " + int.class.getSimpleName());

		try {
			Class consClass = Class.forName("na.learn.java.smalltests.ConstructorClass");

			Constructor cons = consClass.getConstructor(integerCls);
			System.out.println(cons
					.newInstance(new Object[] { new Integer(2) }));

			cons = consClass.getConstructor(intCls);
			System.out.println(cons.newInstance(new Object[] { 2 }));

			// primitives also have a class
			// Every array also belongs to a class that is reflected as 
			// a Class object that is shared by all arrays
			// with the same element type and number of dimensions. 
			int[] intArray2 = { 2, 3 };
			int[] intArray3 = { 2, 3, 4 };
			int[][] intArray4 = { { 2, 3, 4 }, { 5, 6 } };
			int[][] intArray5 = { { 1, 11, 111 }, { 22, 22 } };
			System.out.println("Class of int[] {2,3} is: "
					+ intArray2.getClass().getSimpleName());
			System.out.println("Class of int[] {2,3,4} is: "
					+ intArray3.getClass().getSimpleName());
			System.out.println("Class of int[][] {{2,3,4},{5,6}} is: "
					+ intArray4.getClass().getSimpleName());
			System.out.println("intArray4 == intArray5 is :"
					+ (intArray4.getClass() == intArray5.getClass()));

			//No such method exists.
		//	Method meth = consClass.getMethod("nonExistingFunc", null);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
